package response

import (
	"github.com/tal-tech/go-zero/rest/httpx"
	"net/http"
)

type Body struct {
	Code int	`json:"code"`
	Msg string	`json:"msg"`
	Data interface{}	`json:"data"`
}
func FailureResponse(resp interface{},message string,code int) Body {
	return Body{Code:code,Msg: message,Data: resp}
}

func Response(w http.ResponseWriter,resp interface{},err error)  {
	var body Body
	if err!=nil{
		body.Code=500
		body.Msg=err.Error()
	}else {
		body.Code=200
		body.Msg="OK"
		body.Data=resp
	}
	httpx.OkJson(w,body)
}